package com.wzapp.sitposture.task.endpoint;

import com.wzapp.sitposture.common.annotation.Task;
import com.wzapp.sitposture.common.constant.RestTaskConstant;
import com.wzapp.sitposture.common.error.CustomizedException;
import com.wzapp.sitposture.eshop.service.OrderService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RestController;

import java.security.Principal;

/**
 * 功能: <br/>
 *
 * @author ql
 * @version 0.4
 * @create 2018-09-25 10:56
 **/
@Slf4j
@RestController
public class RestTaskEndpoint {

    @Autowired
    OrderService orderService;

    @GetMapping("/task/restTasks/action/{task}")
    public ResponseEntity executeTasks(@PathVariable String task, Principal principal) throws CustomizedException {

        switch (task){
            case RestTaskConstant.AUTO_CREATE_ORDER :
                orderService.autoCreateOrder();
                break;

            //清理未付费用户环信账户
            case RestTaskConstant.AUTO_DELETE_UNPAID_USER_HUANXIN :
                orderService.autoDeleteUnpaidUserHuanXin();
                break;
            default:
                throw new CustomizedException("public.api.notsupport");
        }
        return null;
    }
}
